package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.HomeClassBeen;
import cn.xfdzx.android.apps.shop.bean.HomeSearchXFDGoodBeen;

/**
 * @author gzk
 * @date 2020/3/28 0028
 * description：搜索结果商店水果类
 */
public class SearchShopGoodsGVAdapter extends BaseAdapter {

    private Context mContext;
    private List<HomeSearchXFDGoodBeen.GoodsBeenSan> mList;

    private TextView tvNowPrice;
    private TextView tvOldPrice;
    private ImageView ivShopSanGood;

    public SearchShopGoodsGVAdapter(Context mContext, List<HomeSearchXFDGoodBeen.GoodsBeenSan> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size()>3?3:mList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(mContext, R.layout.item_search_shop_goods, null);

        ivShopSanGood = view.findViewById(R.id.iv_shop_san_good);
        tvNowPrice = view.findViewById(R.id.tv_now_price);
        tvOldPrice = view.findViewById(R.id.tv_old_price);
        tvOldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);



        Glide.with(mContext).load(mList.get(i).getThumb()).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(ivShopSanGood);

        if (Double.parseDouble(mList.get(i).getDiscountprice())==0){
            tvNowPrice.setText("¥"+mList.get(i).getMarketprice()+"");
//            tvOldPrice.setText("¥"+mList.get(i).getProductprice()+"");
            tvOldPrice.setVisibility(View.GONE);
        }else {
            tvOldPrice.setVisibility(View.VISIBLE);
            tvNowPrice.setText("¥"+mList.get(i).getDiscountprice()+"");
            tvOldPrice.setText("¥"+mList.get(i).getMarketprice()+"");
        }
       return view;
    }
}
